import { IFeidaoAiBrowserComponent } from '../../interfaces';
import set from '../local/set';
import stop from './stop';

/**
 * 设定并启动定时器
 * @param fd 系统参数
 * @param id 定时器id
 * @param event_name 响应编号（事件编号）
 * @param timeout 定时器时间间隔
 * @example start_timer(fd,id,event_name,timeout);
 */
export default function start_timer(fd: IFeidaoAiBrowserComponent, id: string, event_name: string, timeout: number) {
	stop(fd, id);
	const handler = setInterval(() => {
		fd.emit(event_name);
	}, timeout);
	set(fd, `fd-timer-${id}`, handler);
}
